﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.BIM;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HYSpace
{
	public partial class FrmModifyTimeAssign : System.Windows.Forms.Form
	{
		public FrmModifyTimeAssign()
		{
			this.InitializeComponent();
		}

		public FrmModifyTimeAssign(string taName, IList<TimeAssign> listTimeAssign)
		{
			this.InitializeComponent();
			this.listTA = listTimeAssign;
			this.timeName = taName;
		}

		private void FrmModifyTimeAssign_Load(object sender, EventArgs e)
		{
			string[] source = new string[]
			{
				"人员_默认",
				"新风_默认",
				"照明_默认",
				"电子设备_默认",
				"电热设备_默认",
				"电动设备_默认"
			};
			foreach (TimeAssign timeAssign in this.listTA)
			{
				if (timeAssign.TsName == this.timeName)
				{
					int startIndex = timeAssign.TsName.IndexOf("_") + 1;
					this.txtTimeName.Text = timeAssign.TsName.Substring(startIndex);
					this.txtTimeType.Text = timeAssign.TsParent;
					this.txtType.Text = timeAssign.Id.ToString();
					this.SetTimeInfo(timeAssign);
					this.nodeText = timeAssign.TsName;
				}
				if (source.Contains(timeAssign.TsName))
				{
					this.txtTimeName.ReadOnly = true;
                    this.txtTimeName.BackColor = System.Drawing.Color.AliceBlue;
				}
			}
			this.txtTimeName.Focus();
			this.txtTimeName.Select();
		}

		public void SetTimeInfo(TimeAssign timeAssign)
		{
			this.ucTimeAssign1.txt00.Text = StringTools.CutOffEfficacious(timeAssign.T0.ToString(), 2);
			this.ucTimeAssign1.txt00.Tag = this.ucTimeAssign1.txt00.Text;
			this.ucTimeAssign1.txt01.Text = StringTools.CutOffEfficacious(timeAssign.T1.ToString(), 2);
			this.ucTimeAssign1.txt01.Tag = this.ucTimeAssign1.txt01.Text;
			this.ucTimeAssign1.txt02.Text = StringTools.CutOffEfficacious(timeAssign.T2.ToString(), 2);
			this.ucTimeAssign1.txt02.Tag = this.ucTimeAssign1.txt02.Text;
			this.ucTimeAssign1.txt03.Text = StringTools.CutOffEfficacious(timeAssign.T3.ToString(), 2);
			this.ucTimeAssign1.txt03.Tag = this.ucTimeAssign1.txt03.Text;
			this.ucTimeAssign1.txt04.Text = StringTools.CutOffEfficacious(timeAssign.T4.ToString(), 2);
			this.ucTimeAssign1.txt04.Tag = this.ucTimeAssign1.txt04.Text;
			this.ucTimeAssign1.txt05.Text = StringTools.CutOffEfficacious(timeAssign.T5.ToString(), 2);
			this.ucTimeAssign1.txt05.Tag = this.ucTimeAssign1.txt05.Text;
			this.ucTimeAssign1.txt06.Text = StringTools.CutOffEfficacious(timeAssign.T6.ToString(), 2);
			this.ucTimeAssign1.txt06.Tag = this.ucTimeAssign1.txt06.Text;
			this.ucTimeAssign1.txt07.Text = StringTools.CutOffEfficacious(timeAssign.T7.ToString(), 2);
			this.ucTimeAssign1.txt07.Tag = this.ucTimeAssign1.txt07.Text;
			this.ucTimeAssign1.txt08.Text = StringTools.CutOffEfficacious(timeAssign.T8.ToString(), 2);
			this.ucTimeAssign1.txt08.Tag = this.ucTimeAssign1.txt08.Text;
			this.ucTimeAssign1.txt09.Text = StringTools.CutOffEfficacious(timeAssign.T9.ToString(), 2);
			this.ucTimeAssign1.txt09.Tag = this.ucTimeAssign1.txt09.Text;
			this.ucTimeAssign1.txt10.Text = StringTools.CutOffEfficacious(timeAssign.T10.ToString(), 2);
			this.ucTimeAssign1.txt10.Tag = this.ucTimeAssign1.txt10.Text;
			this.ucTimeAssign1.txt11.Text = StringTools.CutOffEfficacious(timeAssign.T11.ToString(), 2);
			this.ucTimeAssign1.txt11.Tag = this.ucTimeAssign1.txt11.Text;
			this.ucTimeAssign1.txt12.Text = StringTools.CutOffEfficacious(timeAssign.T12.ToString(), 2);
			this.ucTimeAssign1.txt12.Tag = this.ucTimeAssign1.txt12.Text;
			this.ucTimeAssign1.txt13.Text = StringTools.CutOffEfficacious(timeAssign.T13.ToString(), 2);
			this.ucTimeAssign1.txt13.Tag = this.ucTimeAssign1.txt13.Text;
			this.ucTimeAssign1.txt14.Text = StringTools.CutOffEfficacious(timeAssign.T14.ToString(), 2);
			this.ucTimeAssign1.txt14.Tag = this.ucTimeAssign1.txt14.Text;
			this.ucTimeAssign1.txt15.Text = StringTools.CutOffEfficacious(timeAssign.T15.ToString(), 2);
			this.ucTimeAssign1.txt15.Tag = this.ucTimeAssign1.txt15.Text;
			this.ucTimeAssign1.txt16.Text = StringTools.CutOffEfficacious(timeAssign.T16.ToString(), 2);
			this.ucTimeAssign1.txt16.Tag = this.ucTimeAssign1.txt16.Text;
			this.ucTimeAssign1.txt17.Text = StringTools.CutOffEfficacious(timeAssign.T17.ToString(), 2);
			this.ucTimeAssign1.txt17.Tag = this.ucTimeAssign1.txt17.Text;
			this.ucTimeAssign1.txt18.Text = StringTools.CutOffEfficacious(timeAssign.T18.ToString(), 2);
			this.ucTimeAssign1.txt18.Tag = this.ucTimeAssign1.txt18.Text;
			this.ucTimeAssign1.txt19.Text = StringTools.CutOffEfficacious(timeAssign.T19.ToString(), 2);
			this.ucTimeAssign1.txt19.Tag = this.ucTimeAssign1.txt19.Text;
			this.ucTimeAssign1.txt20.Text = StringTools.CutOffEfficacious(timeAssign.T20.ToString(), 2);
			this.ucTimeAssign1.txt20.Tag = this.ucTimeAssign1.txt20.Text;
			this.ucTimeAssign1.txt21.Text = StringTools.CutOffEfficacious(timeAssign.T21.ToString(), 2);
			this.ucTimeAssign1.txt21.Tag = this.ucTimeAssign1.txt21.Text;
			this.ucTimeAssign1.txt22.Text = StringTools.CutOffEfficacious(timeAssign.T22.ToString(), 2);
			this.ucTimeAssign1.txt22.Tag = this.ucTimeAssign1.txt22.Text;
			this.ucTimeAssign1.txt23.Text = StringTools.CutOffEfficacious(timeAssign.T23.ToString(), 2);
			this.ucTimeAssign1.txt23.Tag = this.ucTimeAssign1.txt23.Text;
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
			base.Close();
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			foreach (TimeAssign timeAssign in this.listTA)
			{
				if (timeAssign.Id.ToString() == this.txtType.Text)
				{
					timeAssign.TsParent = this.txtTimeType.Text;
					timeAssign.TsName = timeAssign.TsParent + "_" + this.txtTimeName.Text;
					this.SetTextToTA(timeAssign);
					this.nodeText = timeAssign.TsParent + "_" + this.txtTimeName.Text;
					this.tAssign = timeAssign;
				}
			}
			base.DialogResult = DialogResult.OK;
		}

		public void SetTextToTA(TimeAssign timeAssign)
		{
			timeAssign.T0 = Convert.ToDouble(this.ucTimeAssign1.txt00.Text);
			timeAssign.T1 = Convert.ToDouble(this.ucTimeAssign1.txt01.Text);
			timeAssign.T2 = Convert.ToDouble(this.ucTimeAssign1.txt02.Text);
			timeAssign.T3 = Convert.ToDouble(this.ucTimeAssign1.txt03.Text);
			timeAssign.T4 = Convert.ToDouble(this.ucTimeAssign1.txt04.Text);
			timeAssign.T5 = Convert.ToDouble(this.ucTimeAssign1.txt05.Text);
			timeAssign.T6 = Convert.ToDouble(this.ucTimeAssign1.txt06.Text);
			timeAssign.T7 = Convert.ToDouble(this.ucTimeAssign1.txt07.Text);
			timeAssign.T8 = Convert.ToDouble(this.ucTimeAssign1.txt08.Text);
			timeAssign.T9 = Convert.ToDouble(this.ucTimeAssign1.txt09.Text);
			timeAssign.T10 = Convert.ToDouble(this.ucTimeAssign1.txt10.Text);
			timeAssign.T11 = Convert.ToDouble(this.ucTimeAssign1.txt11.Text);
			timeAssign.T12 = Convert.ToDouble(this.ucTimeAssign1.txt12.Text);
			timeAssign.T13 = Convert.ToDouble(this.ucTimeAssign1.txt13.Text);
			timeAssign.T14 = Convert.ToDouble(this.ucTimeAssign1.txt14.Text);
			timeAssign.T15 = Convert.ToDouble(this.ucTimeAssign1.txt15.Text);
			timeAssign.T16 = Convert.ToDouble(this.ucTimeAssign1.txt16.Text);
			timeAssign.T17 = Convert.ToDouble(this.ucTimeAssign1.txt17.Text);
			timeAssign.T18 = Convert.ToDouble(this.ucTimeAssign1.txt18.Text);
			timeAssign.T19 = Convert.ToDouble(this.ucTimeAssign1.txt19.Text);
			timeAssign.T20 = Convert.ToDouble(this.ucTimeAssign1.txt12.Text);
			timeAssign.T21 = Convert.ToDouble(this.ucTimeAssign1.txt21.Text);
			timeAssign.T22 = Convert.ToDouble(this.ucTimeAssign1.txt22.Text);
			timeAssign.T23 = Convert.ToDouble(this.ucTimeAssign1.txt23.Text);
		}

		private void txtType_Leave(object sender, EventArgs e)
		{
			foreach (TimeAssign timeAssign in this.listTA)
			{
				if (timeAssign.TsName == this.txtTimeType + "_" + this.txtTimeName.Text && timeAssign.TsName != this.nodeText)
				{
					YJKMessageBox.Show("不能与已有的时间表名相同！");
					this.txtTimeName.Focus();
					this.txtTimeName.Select();
				}
			}
		}

		public IList<TimeAssign> listTA = new List<TimeAssign>();

		private string timeName = "";

		public string nodeText = "";

		public TimeAssign tAssign = new TimeAssign();
	}
}
